WndProc proc hWin:DWORD,localMsg:DWORD,wParam :DWORD,lParam :DWORD
        local hDC:HDC
        local i:SDWORD,iType:SDWORD
        local ps:PAINTSTRUCT
        local szBuffer[128]:BYTE,szKeyName[32]:BYTE
        local tm:TEXTMETRIC
        local SESI:DWORD
    .if localMsg == WM_CREATE
		jmp PORCINIT
	.elseif localMsg == WM_DISPLAYCHANGE
		PORCINIT:
		invoke GetSystemMetrics,SM_CXMAXIMIZED
		mov cxClientMax,eax
		invoke GetSystemMetrics,SM_CYMAXIMIZED
		mov cyClientMax,eax
		invoke GetDC,hWin
		mov hDC,eax
		invoke GetStockObject,ANSI_FIXED_FONT
		invoke SelectObject,hDC,eax
		invoke GetTextMetrics,hDC,ADDR tm
		mov eax,tm.tmAveCharWidth
		mov cxChar,eax
		mov eax,tm.tmHeight
		mov cyChar,eax
		invoke ReleaseDC,hWin,hDC
		mov eax,pmsg
		.if eax != 0
			invoke GlobalFree,eax
			;xor eax,eax
			;mov pmsg,eax;pmsg=NULL
		.endif
		mov eax,cyClientMax
		cdq
		div cyChar
		mov cLinesMax,eax
		imul eax,SIZEOF MSG
		invoke GlobalAlloc,GPTR,eax
		.if eax == 0
			call ErrorHandler
			invoke PostQuitMessage,NULL
		.endif
		mov pmsg,eax
		mov cLines,0
		
	.elseif localMsg == WM_SIZE
		mov eax,lParam
		and eax,0ffffh
		mov cxClient,eax
		mov eax,lParam
		shr eax,16
		clc
		and eax,0ffffh
		mov cyClient,eax
		mov eax,cxClient
		mov rectScroll.left,0
		mov eax,cxClient
		mov rectScroll.right,eax
		mov eax,cyChar
		mov rectScroll.top,eax
		mov eax,cyClient
		cdq
		div cyChar
		imul eax,cyChar
		mov rectScroll.bottom,eax
		invoke InvalidateRect,hWin,NULL,TRUE
		xor eax,eax
		ret
	.elseif localMsg == WM_KEYDOWN
		jmp ISKEYDOWN
	.elseif localMsg == WM_KEYUP
		jmp ISKEYDOWN
	.elseif localMsg == WM_CHAR
		jmp ISKEYDOWN
	.elseif localMsg == WM_DEADCHAR
		jmp ISKEYDOWN
	.elseif localMsg == WM_SYSKEYDOWN
		jmp ISKEYDOWN
	.elseif localMsg == WM_SYSKEYUP
		jmp ISKEYDOWN
	.elseif localMsg == WM_SYSCHAR
		jmp ISKEYDOWN
	.elseif localMsg == WM_SYSDEADCHAR
		ISKEYDOWN:
		mov eax,cLinesMax
		dec eax
		mov i,eax
		.WHILE eax > 0
			imul eax,size MSG
			add eax,pmsg
			push edi
			mov edi,eax
			mov eax,i
			dec eax
			imul eax,size MSG
			add eax,pmsg
			push esi
			mov esi,eax
			mov ecx,size MSG
			cld
			rep movsb
			pop esi
			pop edi
			dec i
			mov eax,i
		.ENDW
		push edi
		mov edi,pmsg
		mov eax,hWin
		mov (MSG PTR [edi]).hwnd,eax
		mov eax,localMsg
		mov (MSG PTR [edi]).message,eax
		mov eax,wParam
		mov (MSG PTR [edi]).wParam,eax
		mov eax,lParam
		mov (MSG PTR [edi]).lParam,eax
		pop edi
		mov eax,cLines
		inc eax
		cmp eax,cLinesMax
		jl cLineL_
		mov eax,cLinesMax
		mov cLines,eax
		jmp cLineN_
		cLineL_:mov cLines,eax
		cLineN_:mov eax,cyChar
		NEG eax
		invoke ScrollWindow,hWin,0,eax,ADDR rectScroll,ADDR rectScroll
		;XOR eax,eax
		;ret
	.elseif localMsg == WM_DESTROY
		invoke PostQuitMessage,NULL
	.elseif localMsg == WM_CLOSE
		invoke PostQuitMessage,NULL
	.elseif localMsg == WM_PAINT
		invoke BeginPaint,hWin,ADDR ps
		mov hDC,eax
		invoke GetStockObject,SYSTEM_FIXED_FONT
		invoke SetBkMode,hDC,eax
		;invoke GetStockObject,SYSTEM_FIXED_FONT
		;invoke SelectObject,hDC,eax
		invoke TextOut,hDC,0,0,ADDR szTop,lszTop
		invoke TextOut,hDC,0,0,ADDR szUnd,lszUnd
		mov i,0
		mov eax,cyClient
		cdq
		div cyChar
		dec eax
		cmp eax,cLines
		jl CYCLL_1
		mov eax,cLines
		CYCLL_1:
		.WHILE i < eax
			mov SESI,ESI
			mov esi,pmsg
			mov eax,sizeof MSG
			imul eax,i
			add esi,eax
			mov eax,(MSG PTR [esi]).message
			cmp eax,WM_SYSDEADCHAR
			je MSGBINGO
			cmp eax,WM_DEADCHAR
			je MSGBINGO
			cmp eax,WM_SYSCHAR
			je MSGBINGO
			CMP eax,WM_CHAR
			je MSGBINGO
			mov iType,0
			JMP MSGNOTBINGO
			MSGBINGO:mov iType,1
			MSGNOTBINGO:invoke GetKeyNameText,(MSG PTR [esi]).lParam,ADDR szKeyName,sizeof szKeyName
			TestTran:mov eax,(MSG PTR [esi]).lParam
			and eax,080000000h
			jne TranDown
			lea edx,szUp
			push edx
			jmp TestPrev
			TranDown:lea edx,szDown
			push edx
			TestPrev:mov eax,(MSG PTR [esi]).lParam
			and eax,040000000h
			jne PrevUp
			lea edx,szDown
			push edx
			jmp TestALT
			PrevUp:
			lea edx,szUp
			push edx
			TestALT:mov eax,(MSG PTR [esi]).lParam
			and eax,020000000h
			jne ALTNo
			lea edx,szYes
			push edx
			jmp TestExt
			ALTNo:lea edx,szNo
			push edx
			TestExt:mov eax,(MSG PTR [esi]).lParam
			and eax,01000000h
			jne ExtNo
			lea edx,szYes
			push edx
			jmp TestScan
			ExtNo:lea edx,szNo
			push edx
			TestScan:mov eax,(MSG PTR [esi]).lParam
			shr eax,16
			clc
			and eax,0ffh
			push eax
			mov eax,(MSG PTR [esi]).lParam
			and eax,0ffffh
			push eax
			cmp iType,0
			jne CHARANDKEYBINGO
			xor eax,eax
			mov al," "
			push eax
			lea edx,szKeyName
			push edx
			jmp CHARANDKEYNOTBINGO
			CHARANDKEYBINGO:mov eax,(MSG PTR [esi]).wParam
			push eax
			lea edx,szSpace
			push edx
			CHARANDKEYNOTBINGO:push (MSG PTR [esi]).wParam
			mov eax,(MSG PTR [esi]).message
			sub eax,WM_KEYFIRST
			imul eax,sizeof szMessage
			lea edx,szMessage
			add edx,eax
			push edx
			cmp iType,1
			je For_mat2
			lea eax,szFormat1
			push eax
			jmp For_mat1
			For_mat2:lea eax,szFormat2
			push eax
			For_mat1:
			lea eax,szBuffer
			push eax
			call wsprintf
			push eax
			lea eax,szBuffer
			push eax
			mov eax,cyClient
			cdq
			div cyChar
			dec eax
			sub eax,i
			imul eax,cyChar
			push eax
			push 0
			push hDC
			call TextOut
			mov ESI,SESI
			inc i
			mov eax,cyClient
			cdq
			div cyChar
			dec eax
			cmp eax,cLines
			jl CYCLL_2
			mov eax,cLines
			CYCLL_2:
		.ENDW
		invoke EndPaint,hWin,ADDR ps
	.else
		invoke DefWindowProc,hWin,localMsg,wParam,lParam
		ret
	.endif
	invoke DefWindowProc,hWin,localMsg,wParam,lParam
	ret
WndProc endp